package com.project.class4_12.lambda;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.function.Predicate;
import java.util.stream.Collectors;

public class ManTest {
    public static void main(String[] args) {
        ManTest man=new ManTest();
        man.addList();
        List<Man>  list =man.getList();
//        System.out.println(list);
        System.out.println("--------");
//        for (Man m:list){
//            System.out.println(m);
//        }
//        System.out.println("---Lambda-----");
//        list.stream().forEach(l -> System.out.println(l));
//
//        list.stream().forEach(System.out::println);
        System.out.println(list);
        System.out.println("----");
//        list.forEach(l-> System.out.println(l));
        //筛选出工资大于5000的人
//        list.stream().filter(m-> m.getSalary() >5000 ).forEach(e -> System.out.println(e));
        //排序
//        list.stream().sorted(((o1, o2) -> o1.getSalary()-o2.getSalary())).forEach( r-> System.out.print(r));

      //  多次筛选
//        list.stream().filter(s -> s.getSalary()>=5000).sorted((o1, o2) -> o1.getSalary()-o2.getSalary() ).forEach(e -> System.out.println(e));
        //d得到姓张的人数
        long num=list.stream().filter( m -> m.getName().startsWith("吴")).count();
        System.out.println(num);


        //将stream筛选的结果，重新创建新的集合
        List<Man> array=  list.stream().filter(m -> m.getName().startsWith("吴")).collect(Collectors.toList());
        System.out.println(array);





    }
    private List<Man> list=new ArrayList<>();
    public List<Man> getList(){
        return this.list;
    }
    public void addList(){
        list.add(new Man(1,"吴杰",3000));
        list.add(new Man(9,"吴亦凡",6000));
        list.add(new Man(3,"李杨杨",5000));
        list.add(new Man(8,"文林挥",4700));
        list.add(new Man(5,"吴强",8500));
        list.add(new Man(2,"杨洋",1500));
//        list.sort((o1, o2) -> o1.getSalary()-o2.getSalary());
    }
}
